ENT.Type = "brush"

function ENT:AcceptInput(name, activator, caller)
	if name == "createpointentity" then
		local ent = ents.Create("point_checkpoint")
		if ent:IsValid() then
			ent:SetPos(self:LocalToWorld(self:OBBCenter()))
			ent:SetKeyValue("radius", 1)
			ent:SetPoint(self:GetPoint())
			ent:Spawn()
		end

		return true
	end
end

function ENT:Initialize()
	self:Fire("createpointentity", "", 2)

	self:SetTrigger(true)
end

function ENT:KeyValue(key, value)
	if key == "point" then
		self:SetPoint(tonumber(value))
		GAMEMODE.MaxCheckpoint = math.max(GAMEMODE.MaxCheckpoint, self:GetPoint())
		gmod.BroadcastLua("GAMEMODE.MaxCheckpoint="..tostring(GAMEMODE.MaxCheckpoint))
	end
end

function ENT:Touch(ent)
	if ent.IsHoverGear then
		local owner = ent:GetVehicleOwner()
		if owner:IsValid() and owner:Alive() and owner:Team() == TEAM_RACING then
			gamemode.Call("PlayerHitCheckpoint", owner, self:GetPoint())
		end
	end
end

function ENT:SetPoint(point)
	self.Point = point
end

function ENT:GetPoint()
	return self.Point or 0
end
